/*
 * $Id: AOItemBase.java 27 2013-05-20 13:31:39Z antonyhands@gmail.com $
 */
package ru.olympus.antonyhands.ao.data.entities;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import ru.olympus.antonyhands.ao.util.StringPair;

/**
 * @author AntonyHands
 * @since 14.02.2012
 */
public abstract class AOItemBase implements IPersistentClass
{
    public static final String ATTRIBUTE_CODE = "code";
    public static final String ATTRIBUTE_TITLE = "title";

    /**
     * Кодовое название (на английском)
     */
    private String code;

    /**
     * Название на русском
     */
    private String title;

    public AOItemBase()
    {
        // for the sake of persistence
    }

    public AOItemBase(String code, String title)
    {
        this.code = code;
        this.title = title;
    }

    @Override
    public List<StringPair> getAttributes()
    {
        List<StringPair> list = new ArrayList<StringPair>();
        list.add(new StringPair(ATTRIBUTE_CODE, code));
        list.add(new StringPair(ATTRIBUTE_TITLE, title));
        return list;
    }

    @Override
    public void setAttributes(List<StringPair> attributes)
    {
        for (StringPair pair : attributes)
        {
            if (ATTRIBUTE_CODE.equals(pair.getKey()))
                code = pair.getValue();
            else if (ATTRIBUTE_TITLE.equals(pair.getKey()))
                title = pair.getValue();
        }
    }

    public void setCode(String code)
    {
        this.code = code;
    }

    public String getCode()
    {
        return code;
    }

    public void setTitle(String title)
    {
        this.title = title;
    }

    public String getTitle()
    {
        return title;
    }

    @Override
    public Collection<IPersistentClass> getPersistentChildren()
    {
        return new ArrayList<IPersistentClass>();
    }

    @Override
    public void setPersistentChildren(List<IPersistentClass> persistentChildren)
    {
        // do nothing
    }
}
